#include "PrioritySpinBox.h"

PrioritySpinBox::PrioritySpinBox(QWidget *parent) :
	QSpinBox(parent)
{
	priorities << "Low" << "Average" << "High";
	setRange(0, 2);
}

int PrioritySpinBox::valueFromText(const QString &text) const
{
	for (int i = 0; i < 3; i++) {
		if (priorities[i] == text) {
			return i;
		}
	}
	return -1;
}

QString PrioritySpinBox::textFromValue(int val) const
{
	if (val >= 0 && val < priorities.size()) {
		return priorities[val];
	}
	return "";
}

QValidator::State PrioritySpinBox::validate(QString &input, int &pos) const
{
	if (priorities.contains(input, Qt::CaseInsensitive)) {
		return QValidator::Acceptable;
	} else {
		foreach (QString p, priorities) {
			if (p.startsWith(input, Qt::CaseInsensitive)) {
				return QValidator::Intermediate;
			}
		}
	}
	return QValidator::Invalid;
}
